<?php

/**
 * news actions.
 *
 * @package    DUYTAN
 * @subpackage news
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class newsActions extends sfActions
{
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeIndex(sfWebRequest $request)
  {
    //Get all images slides
	$q = Doctrine_Query::create()
		->from('DtCms c')
		->where('c.category_id = ?', 1);
	$this->slides = $q->fetchArray();
	
	//Get copyright
	$this->copyright = "";
	$c = Doctrine_Core::getTable('DtPage')->findOneByAlias('copyright');
	if ($c)
		$this->copyright = $c->content;
	
	$category_id = 2;
	if ($request->getParameter('category_id'))
		$category_id = $request->getParameter('category_id');
	
	//Get list news	
	$q = Doctrine_Query::create()
		->from('DtCms c')
		->where('c.category_id = ?', $category_id);
		
	$this->pager = new sfDoctrinePager('DtCms', 20);
	$this->pager->setQuery($q);
	$this->pager->setPage($request->getParameter('page', 1));
	$this->pager->init();
	
    return SfView::SUCCESS;
  }
  
  public function executePermalink(sfWebRequest $request) 
  {
	//Get all images slides
	$q = Doctrine_Query::create()
		->from('DtCms c')
		->where('c.category_id = ?', 1);
	$this->slides = $q->fetchArray();
	
	//Get copyright
	$this->copyright = "";
	$c = Doctrine_Core::getTable('DtPage')->findOneByAlias('copyright');
	if ($c)
		$this->copyright = $c->content;
		
	$this->cms = NULL;
	$c = Doctrine_Core::getTable('DtCms')->findOneById($request->getParameter('cms_id'));
	if ($c) {
		$this->cms = $c;
	}
	
	$this->cms_others = NULL;
	
	$q = Doctrine_Query::create()
		->from('DtCms c')
		->where('c.category_id = ?', $c->category_id)
		->andWhere('c.id <> ?', $c->id);
		
	$this->cms_others = $q->fetchArray();
	
	return SfView::SUCCESS;
  }
}
